package com.koron.common.core.business.datadict.service;

import com.koron.bean.base.Response;
import com.koron.common.core.business.datadict.bean.po.SysDataDictClassify;
import com.koron.common.core.business.datadict.mapper.SysDataDictClassifyMapper;
import org.koron.ebs.mybatis.SessionFactory;
import org.koron.ebs.mybatis.TaskAnnotation;
import org.springframework.stereotype.Service;

import java.util.List;


/**
 * 系统管理-数据字典分类{@code SysDataDictClassify}表服务实现类
 *
 * <p>方法1-getDictionaryClassifyList：查询数据字典分类的所有数据</p>
 * <p>方法2-getNameById：通过classifyId查出对应的classifyName</p>
 *
 * @author 朱超
 * @since 2021-08-27
 */
@Service
public class SysDataDictClassifyService {

    /**
     * 仅查询数据字典分类的所有数据
     *
     * @param factory
     * @return Response对象
     * @see Response
     * @version 1.0
     */
    @TaskAnnotation("getDictionaryClassifyList")
    public Response getDictionaryClassifyList(SessionFactory factory) {
        SysDataDictClassifyMapper sysDataDictClassifyMapper = factory.getMapper(SysDataDictClassifyMapper.class);
        List<SysDataDictClassify> result = sysDataDictClassifyMapper.getList(new SysDataDictClassify());
        return Response.success(result);
    }

    /**
     * 通过classifyId查出对应的classifyName
     *
     * @param factory
     * @param classifyId 数据字典分类id
     * @return classifyName 数据字典名称
     * @version 1.0
     */
    public String getNameById(SessionFactory factory, String classifyId) {
        SysDataDictClassifyMapper sysDataDictClassifyMapper = factory.getMapper(SysDataDictClassifyMapper.class);
        String classifyName = sysDataDictClassifyMapper.getNameById(classifyId);
        return classifyName;
    }
}